package net.orange.architecture.validator;

/**
 * The base validator which can perform one specify logic validations.
 */
public abstract class ObjectValidator {

	/**
	 * Perform the validation,
	 * 
	 * @return True for pass, False for fail.
	 * @throws Exception
	 */
	public abstract boolean check() throws Exception;

	/**
	 * validate if the object is correct
	 * 
	 * @return "" if correct, the detail error/warning if wrong
	 * @throws Exception
	 */
	public String validate() throws Exception {
		return !check() ? getMessage() : null;
	}

	/**
	 * Format the error/warning message when the validation is not pass.
	 * 
	 * @return The error/warning message.
	 */
	public abstract String getMessage();
}
